package com.tjsinfo.tjsoa.message.vo;

import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.common.BigAnt;
public class TjsMessage {
	private Integer id;
	private Date datetime;
	private Integer senduserid;
	private Integer recuserid;
	private String  sendusername;
	private String  recusername;
	private String  title;
	private String  value;
	private String  link;
	private String  colname;
	private Integer backup1;
	private Integer backup2;
	private String  backup3;
	private String  backup4;
	public String getColname() {
		return colname;
	}
	public void setColname(String colname) {
		this.colname = colname;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Date getDatetime() {
		return datetime;
	}
	public void setDatetime(Date datetime) {
		this.datetime = datetime;
	}
	public Integer getSenduserid() {
		return senduserid;
	}
	public void setSenduserid(Integer senduserid) {
		this.senduserid = senduserid;
	}
	public Integer getRecuserid() {
		return recuserid;
	}
	public void setRecuserid(Integer recuserid) {
		this.recuserid = recuserid;
	}
	public String getSendusername() {
		return sendusername;
	}
	public void setSendusername(String sendusername) {
		this.sendusername = sendusername;
	}
	public String getRecusername() {
		return recusername;
	}
	public void setRecusername(String recusername) {
		this.recusername = recusername;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
	public Integer getBackup1() {
		return backup1;
	}
	public void setBackup1(Integer backup1) {
		this.backup1 = backup1;
	}
	public Integer getBackup2() {
		return backup2;
	}
	public void setBackup2(Integer backup2) {
		this.backup2 = backup2;
	}
	public String getBackup3() {
		return backup3;
	}
	public void setBackup3(String backup3) {
		this.backup3 = backup3;
	}
	public String getBackup4() {
		return backup4;
	}
	public void setBackup4(String backup4) {
		this.backup4 = backup4;
	}
	public TjsMessage() {
	}
	
	private IQbcDao qbcDao;
	private ISystemUserBo systemUserBo;
    private static TjsMessage tjsmessage;  
	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	} 
   
    public IQbcDao getQbcDao() {  
        return qbcDao;  
    }
    
    public void init() 

    { 
    	tjsmessage = this; 
    	tjsmessage.qbcDao = this.qbcDao; 
    	tjsmessage.systemUserBo = this.systemUserBo;
    } 


    
	public static void send(TjsMessage message) {
		if (message.getRecusername()==null || "".equals(message.getRecusername())) {
			if (message.getRecuserid()!=null) {
				DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUser.class);
				criteria.add(Restrictions.eq("userId", message.getRecuserid()));
				
				List<TSystemUser> list = tjsmessage.qbcDao.getCriteria(criteria);
				if (list.size()>0) {
					TSystemUser user = list.get(0);
					if (user.getDataBaseId()!=null) {
						String username  = tjsmessage.systemUserBo.findByIdSystemUserErJiGongSi(user.getDataBaseId(), user.getSubUserId()).getLoginName();
						message.setRecusername(username);
					}else {
						message.setRecusername(user.getUserName());
					}
				}
			}
		}
		try {
			ResourceBundle bundle = ResourceBundle.getBundle("com.tjsinfo.tjsoa.message.properties.message");
			BigAnt.sendMassage(bundle.getString("big_ip"), Integer.valueOf(bundle.getString("big_port")), bundle.getString("big_admin"), bundle.getString("big_password"), message.getValue(), "系统提示", message.getRecusername());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
		
//		BigAnt_api aaa = new BigAnt_api();
//
//		ResourceBundle bundle = ResourceBundle.getBundle("com.tjsinfo.tjsoa.message.properties.message");
//		aaa.setServerIp(bundle.getString("big_ip"));
//		aaa.setServerPort(bundle.getString("big_port"));
//		        
//		aaa.SetModeText();
//
//		aaa.setAccept(message.getRecusername());//接收人
//		
//		aaa.setSander(bundle.getString("big_admin"));//发送人
//		aaa.setSanderPass(bundle.getString("big_password"));
//		aaa.SendMassage("系统提示",message.getValue());
	}
	
	public ISystemUserBo getSystemUserBo() {
		return systemUserBo;
	}
	public void setSystemUserBo(ISystemUserBo systemUserBo) {
		this.systemUserBo = systemUserBo;
	}
}
